package s06;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @ClassName GenericDemo04
 * @Description 通配符高级使用 - 受限泛型
 * @Author Li
 * @Date 2022/8/4 9:15
 * @ModifyDate 2022/8/4 9:15
 * @Version 1.0
 */
public class GenericDemo04 {
    public static void main(String[] args) {
        Collection<Integer> coll1 = new ArrayList<Integer>();
        Collection<String> coll2 = new ArrayList<String>();
        Collection<Number> coll3 = new ArrayList<Number>();
        Collection<Object> coll4 = new ArrayList<Object>();

        // 泛型必须是Number或者Number的子类
        showCollection1(coll1);
        //showCollection1(coll2); // 错误
        showCollection1(coll3);
        //showCollection1(coll4); // 错误

        // 泛型必须是Number或者Number的父类
        //showCollection2(coll1); // 错误
        //showCollection2(coll2); // 错误
        showCollection2(coll3);
        showCollection2(coll4);
    }

    // 泛型的上限：此时的泛型?，必须是Number类型或者Number类型的子类
    public static void showCollection1(Collection<? extends Number> coll) {
    }

    // 泛型的下限：此时的泛型?，必须是Number类型或者Number类型的父类
    public static void showCollection2(Collection<? super Number> coll) {
    }
}
